package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Nyssa;
import com.ruoyi.system.service.INyssaService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 种植果树Controller
 * 
 * @author ruoyi
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/nyssa")
public class NyssaController extends BaseController
{
    @Autowired
    private INyssaService nyssaService;

    /**
     * 查询种植果树列表
     */
    @RequiresPermissions("system:nyssa:list")
    @GetMapping("/list")
    public TableDataInfo list(Nyssa nyssa)
    {
        startPage();
        List<Nyssa> list = nyssaService.selectNyssaList(nyssa);
        return getDataTable(list);
    }

    /**
     * 导出种植果树列表
     */
    @RequiresPermissions("system:nyssa:export")
    @Log(title = "种植果树", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Nyssa nyssa)
    {
        List<Nyssa> list = nyssaService.selectNyssaList(nyssa);
        ExcelUtil<Nyssa> util = new ExcelUtil<Nyssa>(Nyssa.class);
        util.exportExcel(response, list, "种植果树数据");
    }

    /**
     * 获取种植果树详细信息
     */
    @RequiresPermissions("system:nyssa:query")
    @GetMapping(value = "/{nyssaId}")
    public AjaxResult getInfo(@PathVariable("nyssaId") Long nyssaId)
    {
        return success(nyssaService.selectNyssaByNyssaId(nyssaId));
    }

    /**
     * 新增种植果树
     */
    @RequiresPermissions("system:nyssa:add")
    @Log(title = "种植果树", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Nyssa nyssa)
    {
        return toAjax(nyssaService.insertNyssa(nyssa));
    }

    /**
     * 修改种植果树
     */
    @RequiresPermissions("system:nyssa:edit")
    @Log(title = "种植果树", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Nyssa nyssa)
    {
        return toAjax(nyssaService.updateNyssa(nyssa));
    }

    /**
     * 删除种植果树
     */
    @RequiresPermissions("system:nyssa:remove")
    @Log(title = "种植果树", businessType = BusinessType.DELETE)
	@DeleteMapping("/{nyssaIds}")
    public AjaxResult remove(@PathVariable Long[] nyssaIds)
    {
        return toAjax(nyssaService.deleteNyssaByNyssaIds(nyssaIds));
    }
}
